package com.ruoyi.config;

import com.ruoyi.listener.RedisKeyExpirationListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * redis监听配置类
 *
 * @author tanxingxian
 * @date 2022-01-11 10:39
 */
@Configuration
public class RedisListenerConfig {

    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Bean
    RedisMessageListenerContainer redisListenerContainer() {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisConnectionFactory);
        return container;
    }

    @Bean
    public RedisKeyExpirationListener keyExpiredListener() {
        return new RedisKeyExpirationListener(this.redisListenerContainer());
    }

}
